(load "connector.rkt")

(define (squarer a b)
  (define (process-new-value)
    (cond ((has-value? b)
           (if (> 0 (get-value b))
               (error "square less than 0 -- SQUARER" (get-value b))
               (set-value! a
                           (sqrt (get-value b))
                           me)))
          ((has-value? a)
           (set-value! b
                       ((lambda (x) (* x x)) (get-value a))
                       me))))
  (define (process-forget-value)
    (forget-value! a)
    (forget-value! b)
    (process-new-value))
  (define (me request)
    (cond ((eq? request 'I-have-a-value)
           (process-new-value))
          ((eq? request 'I-lost-my-value)
           (process-forget-value))
          (else
           (error "Unknown request -- SQUARER" request))))
  (connect a me)
  (connect b me)
  me)

(define a (make-connector))
(define b (make-connector))
(define s (squarer a b))
(probe 'a a)
(probe 'b b)

(set-value! a 10 'user)